package com.papa91.arcapp;/*package com.papa91.arcapp;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.PixelFormat;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.SimpleAdapter;
import android.widget.SimpleAdapter.ViewBinder;
import android.widget.TextView;
import android.widget.Toast;

import com.papa91.arc.EmuActivity;
import com.papa91.arc.R;
import com.papa91.common.FileUtil;
import com.papa91.common.FileWrapper;

public class GameListAct extends Activity
{
	private View mainView;
	private ListView listView;
	private int lastPosition;

	Button menuBtn;

	boolean overLayEnable;
	boolean overLayVisible;

	private String curDir = null;
	ArrayList<HashMap<String, Object>> listItem;

	ProgressDialog prgDialog = null;
	Exit exit = new Exit();

	private FileWrapper[] listFiles;
	int rowId = -1;
	HashMap<String, String> cnNames;

	void readRomNameFile(String filePath)
	{
		FileInputStream inputStream;
		cnNames = new HashMap<String, String>();
		try
		{
			inputStream = new FileInputStream(filePath);
			InputStreamReader inputReader = new InputStreamReader(inputStream, "GBK");
			BufferedReader br = new BufferedReader(inputReader);
			for (String line = br.readLine(); line != null; line = br.readLine())
			{
				// System.out.println(line);
				line = line.trim();
				int index = line.indexOf(",");
				if (index <= 0 || ((index + 2) >= (line.length() - 1)))
					continue;
				String key = line.substring(0, index);
				String val = line.substring(index + 2, line.length() - 1);
				cnNames.put(key, val);
			}
			br.close();
		} catch (Exception e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void showAdView()
	{
		// LinearLayout container = (LinearLayout)
		// findViewById(R.id.AdLinearLayout);
		// new AdView(this, container).DisplayAd();
	}

	void loadResources()
	{
		prgDialog = ProgressDialog.show(this, (String) this.getResources().getText(R.string.prg_title), (String) this.getResources().getText(R.string.prg_findgame), true);
		new Thread()
		{
			public void run()
			{

				readRomNameFile(AppConfig.INFO_PATH + "listcn.txt");

				//FileUtil.setMode(GameListAct.this, 1, cnNames);
				listFiles = FileUtil.listSortedFiles(new File(curDir));

				fillRoms(listFiles);
			}
		}.start();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		//qyh		AgentApp.getInstance().addActivity(this);
		AppConfig.initialise(GameListAct.this);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);

		LayoutInflater inflater = LayoutInflater.from(this);
		mainView = inflater.inflate(R.layout.listview, null);

		setContentView(mainView);
		wangpuAdInit();

		initOverlay();

		listView = (ListView) this.findViewById(R.id.filelist);
		listView.setLongClickable(true);
		listView.setOnItemClickListener(listClickListener);
		listView.setOnItemLongClickListener(listLongClickListener);
		listView.setOnScrollListener(new ListViewOnScrollListener());
		listView.setOnTouchListener(new OnTouchListener()
		{

			@Override
			public boolean onTouch(View v, MotionEvent event)
			{
				// TODO Auto-generated method stub
				final int action = event.getAction();
				if (action == MotionEvent.ACTION_DOWN)
				{
					overLayEnable = true;
					if (tvOverlay != null)
						tvOverlay.setVisibility(View.INVISIBLE);
				}
				else if (action == MotionEvent.ACTION_UP)
				{
					overLayEnable = false;
					if (tvOverlay != null)
						tvOverlay.setVisibility(View.INVISIBLE);
				}
				return false;
			}
		});

		curDir = AppConfig.getLastDir(this);
		// this.searchAndFillRoms();
		loadResources();

		menuBtn = (Button) this.findViewById(R.id.menuBtn);
		menuBtn.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				//showWindow(v);
			}
		});

		// if (!AppConfig.hideAds(this))
		// showAdView();
	}

	private TextView tvOverlay;
	private WindowManager windowManager;

	private void initOverlay()
	{
		tvOverlay = (TextView) View.inflate(this, R.layout.overlay, null);
		windowManager = getWindowManager();
		WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.TYPE_APPLICATION,
				WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT);
		windowManager.addView(tvOverlay, layoutParams);
	}

	private class ListViewOnScrollListener implements AbsListView.OnScrollListener
	{
		private static final String TAG = "ListViewOnScrollListener";

		@Override
		public void onScrollStateChanged(AbsListView view, int scrollState)
		{
			// Log.i(TAG,"onScrollStateChanged"+scrollState);
			overLayVisible = true;
			if (scrollState == ListView.OnScrollListener.SCROLL_STATE_IDLE || scrollState == ListView.OnScrollListener.SCROLL_STATE_FLING)
			{
				tvOverlay.setVisibility(View.INVISIBLE);
			}
		}

		@Override
		public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount)
		{
			// Log.i(TAG, "onScroll totalItemcount is "+totalItemCount);
			// Log.i(TAG, "onScroll visibleItemCount is "+visibleItemCount);
			if (overLayEnable && overLayVisible && firstVisibleItem >= 0)
			{
				HashMap<String, Object> map = listItem.get(firstVisibleItem + visibleItemCount / 2);
				String path = (String) map.get("GameTitle");

				if (path.length() > 0)
				{
					tvOverlay.setText(path.substring(0, 1));
					tvOverlay.setVisibility(View.VISIBLE);
				}

				if ((firstVisibleItem == 0) || (firstVisibleItem + visibleItemCount == listItem.size()))
				{
					tvOverlay.setVisibility(View.INVISIBLE);
				}
			}
		}
	}

	private String getParentDir()
	{
		int last = curDir.lastIndexOf('/');
		if (last > 0)
		{
			return curDir.substring(0, last);
		}
		else if (last == 0)
			return "/";
		else
			return curDir;
	}

	OnItemClickListener listClickListener = new OnItemClickListener()
	{
		public void onItemClick(AdapterView<?> parent, View view, int position, long id)
		{
			if (tvOverlay != null)
				tvOverlay.setVisibility(View.INVISIBLE);
			rowId = (int) id;
			lastPosition = position;
			if (rowId == 0)
			{
				String updir = getParentDir();
				curDir = updir;
				AppConfig.saveLastDir(GameListAct.this, curDir);

				// fillRoms(new File(updir).listFiles());
				fillRoms(FileUtil.listSortedFiles(new File(updir)));

			}
			else
			{
				HashMap<String, Object> map = listItem.get(rowId);
				String path = (String) map.get("GamePath");
				final File file = new File(path);
				if (file.isDirectory())
				{
					curDir = path;
					AppConfig.saveLastDir(GameListAct.this, curDir);

					// fillRoms(file.listFiles());
					fillRoms(FileUtil.listSortedFiles(file));
				}
				else
				{
					RomOpen();
				}
			}

		}
	};

	OnItemLongClickListener listLongClickListener = new OnItemLongClickListener()
	{

		@Override
		public boolean onItemLongClick(AdapterView<?> arg0, View view, int pos, long id)
		{
			// TODO Auto-generated method stub
			rowId = (int) id;
			lastPosition = pos;
			if (tvOverlay != null)
				tvOverlay.setVisibility(View.INVISIBLE);

			HashMap<String, Object> map = listItem.get(rowId);
			String path = (String) map.get("GamePath");

			File file = new File(path);
			if (file.exists() == false || file.isDirectory())
			{
				return false;
			}

			showRomOperationDlg();

			return false;
		}

	};

	private void searchRoms(FileWrapper[] files)
	{
		HashMap<String, Object> map;
		map = new HashMap<String, Object>();
		map.put("GameThumb", R.drawable.updir);
		map.put("GameTitle", this.getResources().getString(R.string.upLevelDir));
		map.put("GameName", this.curDir);
		map.put("GamePath", this.curDir);
		listItem.add(map);

		if (files == null)
		{
			return;
		}

		BitmapFactory.Options opts = new BitmapFactory.Options();
		opts.inTargetDensity = this.getResources().getDisplayMetrics().densityDpi;
		opts.inDensity = DisplayMetrics.DENSITY_DEFAULT;
		for (FileWrapper file : files)
		{
			if (file.mfile.isDirectory() && !file.mfile.isHidden())
			{

				// searchRoms(file.listFiles());
				String path = file.mfile.getPath();
				{
					map = new HashMap<String, Object>();
					map.put("GameThumb", R.drawable.dir);
					map.put("GameTitle", AppConfig.getNameWithExt(path));
					if (file.mfile.list() != null)
						map.put("GameName", "files:" + file.mfile.list().length);
					map.put("GamePath", path);
					listItem.add(map);
				}
			}
			else if (file.mfile.isFile())
			{
				String path = file.mfile.getPath();
				long fileLen = file.mfile.length();
				String strSize;
				if (fileLen > 1024 * 1024)
					strSize = "  (" + (Math.round((float) fileLen / (1024 * 1024) * 10) / 10f) + " MB)";
				else if (fileLen > 1024)
					strSize = "  (" + ((Math.round((float) fileLen / (1024) * 10) / 10f)) + " KB)";
				else
					strSize = "  (" + fileLen + " Bytes)";
				if (AppConfig.isGameFile(path))
				{
					map = new HashMap<String, Object>();
					String name = AppConfig.getNameNoExt(path).toLowerCase();
					if (Character.isDigit(name.charAt(0)))
						name = "a" + name;

					Bitmap bmp = BitmapFactory.decodeFile(AppConfig.INFO_PATH + "icon/" + name + ".ico", opts);
					if (bmp != null)
					{
						map.put("GameThumb", bmp);
					}
					else
						map.put("GameThumb", R.drawable.games);

					String nameCN = cnNames.get(AppConfig.getNameNoExt(path).toLowerCase());
					if (nameCN != null)
					{
						map.put("GameTitle", nameCN);
						map.put("GameName", AppConfig.getNameWithExt(path) + strSize);
					}
					else
					{
						if (path.endsWith(".fba"))
						{
							map.put("GameTitle", AppConfig.getNameNoExt(path));
							map.put("GameName", "fba game" + strSize);
						}
						else
						{
							map.put("GameTitle", AppConfig.getNameNoExt(path));
							map.put("GameName", AppConfig.getNameWithExt(path) + strSize);
						}
					}
					map.put("GamePath", path);
					listItem.add(map);
				}
			}
		}
	}

	private void fillRoms(FileWrapper[] files)
	{
		listItem = new ArrayList<HashMap<String, Object>>();
		if (files == null)
		{
			handler.sendEmptyMessage(0);
		}

		searchRoms(files);

		handler.sendEmptyMessage(0);
	}

	private Handler handler = new Handler()
	{
		@Override
		// 
		public void handleMessage(Message msg)
		{
			super.handleMessage(msg);
			updateListView();
			if (prgDialog.isShowing())
			{
				// prgDialog.dismiss();
				prgDialog.cancel();
			}
		}
	};

	private void searchAndFillRoms()
	{
		// listFiles = new File(AppConfig.ROM_PATH).listFiles();
		listFiles = FileUtil.listSortedFiles(new File(curDir));
		prgDialog = ProgressDialog.show(this, (String) this.getResources().getText(R.string.prg_title), (String) this.getResources().getText(R.string.prg_findgame), true);
		new Thread()
		{
			public void run()
			{
				fillRoms(listFiles);
			}
		}.start();
	}

	class MySimpleAdapter extends SimpleAdapter
	{

		public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
		{
			super(context, data, resource, from, to);
			// TODO Auto-generated constructor stub
		}

		public View getView(int position, View contentView, ViewGroup parent)
		{

			View row = super.getView(position, contentView, parent);
			//			TextView tvTitle = (TextView) row.findViewById(R.id.GameTitle);
			TextView tvName = (TextView) row.findViewById(R.id.GamePath);
			String name = (String) tvName.getText();
			//			if (AppConfig.isGameFile(name)) {
			//				RomInfo rom = AppConfig.allRomInfo.get(AppConfig.getNameNoExt(
			//						name).toLowerCase());
			//				if (rom == null)
			//					tvTitle.setTextColor(Color.RED);
			//				else
			//					tvTitle.setTextColor(Color.BLACK);
			//			}
			return row;
		}
	}

	private void updateListView()
	{
		SimpleAdapter listItemAdapter = new MySimpleAdapter(this, listItem, // data source
				R.layout.file_row, // xml for listItem
				new String[]
				{ "GameThumb", "GameTitle", "GameName", "GamePath"
				},//
				new int[]
				{ R.id.GameThumb, R.id.GameTitle, R.id.GameName, R.id.GamePath
				});
		listItemAdapter.setViewBinder(new MyViewBinder());
		listView.setAdapter(listItemAdapter);

		if (listItem.size() <= 1)
		{
			Toast.makeText(this, R.string.nofile_found_msg, Toast.LENGTH_SHORT).show();
			return;
		}
		else
		{
			if (lastPosition >= 0 && lastPosition < listView.getCount())
				listView.setSelection(lastPosition);
			else if (listView.getCount() > 0)
				listView.setSelection(listView.getCount() - 1);
		}
	}

	public class MyViewBinder implements ViewBinder
	{

		@Override
		public boolean setViewValue(View arg0, Object arg1, String arg2)
		{
			if ((arg0 instanceof ImageView) & (arg1 instanceof Bitmap))
			{
				ImageView iv = (ImageView) arg0;
				Bitmap bm = (Bitmap) arg1;
				iv.setImageBitmap(bm);
				return true;
			}
			return false;
		}

	}

	public boolean RomOpen()
	{
		//showCompleteDialog(this).show();
		//return true;
		// TODO Auto-generated method stub
		HashMap<String, Object> map = listItem.get(rowId);
		String path = (String) map.get("GamePath");
		File file = new File(path);
		if (file.exists() == false)
		{
			return false;
		}

		String romTitle = (String) map.get("GameTitle");
		if (romTitle.equals(""))
			romTitle = (String) map.get("GameName");
		Intent intent = new Intent();
		// intent.setClass(this, EmuActivity.class);
		intent.setClass(this, EmuActivity.class);
		Bundle bundle = new Bundle();
		path = path.substring(0, path.lastIndexOf("."));
		//		bundle.putString(AppConfig.KEY_ROM_PATH, path);
		//		bundle.putString(AppConfig.KEY_ROM_TITLE, romTitle);
		//		bundle.putInt(AppConfig.KEY_START_MODE, 0);
		String json = "{\"plugin_area_val\":0,\"romPath\":\"" + path + "\",\"startMode\":" + START_MODE + ",\"userID\":\"" + USERID
				+ "\",\"gameID\":\"509474702\",\"version\":\"2\",\"roomID\":\"10010001\",\"serverIP\":\"192.168.43.1\",\"serverPort\":\"17101\",\"porder\":" + PORDER
				+ ",\"p1Name\":\"player1\",\"p2Name\":\"player2\",\"tcptype\":2,\"udpport\":17101}"; //test
		//		;192.168.78.6   121.201.0.114

		bundle.putString(AppConfig.KEY_START_JSON, json);
		//		bundle.putString(AppConfig.KEY_START_GAMEID, GameID);

		intent.putExtras(bundle);
		startActivityForResult(intent, 0);

		AppConfig.logD("RomOpen:" + path);
		return true;
	}

	@Override
	protected void onResume()
	{
		// TODO Auto-generated method stub
		// curDir=AppConfig.getLastDir(this);
		super.onResume();
	}

	@Override
	protected void onPause()
	{
		// TODO Auto-generated method stub
		AppConfig.saveLastDir(this, this.curDir);
		super.onPause();
	}

	@Override
	protected void onDestroy()
	{
		// TODO Auto-generated method stub
		windowManager.removeView(tvOverlay);
		wangpuAdExit();
		super.onDestroy();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// TODO Auto-generated method stub
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.main_options_menu, menu);

		return super.onCreateOptionsMenu(menu);
	}

	public static String USERID = "2000";
	public static int PORDER = 0;
	public static int START_MODE = 0;

	@Override
	public boolean onOptionsItemSelected(MenuItem item)
	{
		// TODO Auto-generated method stub
		super.onOptionsItemSelected(item);

		Intent intent;
		switch (item.getItemId())
		{
			case R.id.player1:
				USERID = "1000";
				PORDER = 0;
				START_MODE = 1;
				break;

			case R.id.player2:
				USERID = "1001";
				PORDER = 1;
				START_MODE = 2;
				break;

			case R.id.fba_core_v1:
				EmuActivity.coreName = "FBA";
				break;

			case R.id.fba_core_v2:
				EmuActivity.coreName = "FBA_V2";
				break;

			case R.id.exit:
				this.finish();
				break;
		}
		return true;
	}

	@Override
	public void onOptionsMenuClosed(Menu menu)
	{
		// TODO Auto-generated method stub
		super.onOptionsMenuClosed(menu);
	}

	@Override
	public boolean onPrepareOptionsMenu(Menu menu)
	{
		// TODO Auto-generated method stub
		return super.onPrepareOptionsMenu(menu);
	}

	class Exit
	{
		private boolean isExit = false;
		private Runnable task = new Runnable()
		{
			@Override
			public void run()
			{
				isExit = false;
			}
		};

		public void doExitInOneSecond()
		{
			isExit = true;
			HandlerThread thread = new HandlerThread("doTask");
			thread.start();
			new Handler(thread.getLooper()).postDelayed(task, 1000);
		}

		public boolean isExit()
		{
			return isExit;
		}

		public void setExit(boolean isExit)
		{
			this.isExit = isExit;
		}
	}

	private void pressAgainExit()
	{
		if (exit.isExit())
		{
			finish();
		}
		else
		{
			Toast.makeText(getApplicationContext(), R.string.exit_msg, Toast.LENGTH_SHORT).show();
			exit.doExitInOneSecond();
		}
	}

	@Override
	public boolean onKeyUp(int keyCode, KeyEvent event)
	{
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK)
		{
			pressAgainExit();
			return true;
		}
		return super.onKeyUp(keyCode, event);
	}

	void wangpuAdInit()
	{
		// AppConnect
		// .getInstance("ceb4d88bbe49ba6ab66cbbb6a49c055f", "gfan", this);
	}

	void wangpuAdExit()
	{
		// AppConnect.getInstance(this).finalize();
	}

	private PopupWindow popupWindow;
	private ListView lv_group;
	private View view;
	private List<String> groups;

	private void showWindow(View parent)
	{

		if (popupWindow == null)
		{
			LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

			view = layoutInflater.inflate(R.layout.game_catagory, null);

			lv_group = (ListView) view.findViewById(R.id.lv_list);
			// 鍔犺浇鏁版嵁
			groups = new ArrayList<String>();
			groups.add(getResources().getString(R.string.RomAll));
			groups.add(getResources().getString(R.string.RomSupport));
			groups.add(getResources().getString(R.string.RomMyFavor));
			groups.add(getResources().getString(R.string.RomSystem));
			groups.add(getResources().getString(R.string.RomGameType));

		//	GroupAdapter groupAdapter = new GroupAdapter(this, groups);
			//lv_group.setAdapter(groupAdapter);
			popupWindow = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
		}

		popupWindow.setFocusable(true);
		popupWindow.setOutsideTouchable(true);

		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);

		int xPos = windowManager.getDefaultDisplay().getWidth() / 2 - popupWindow.getWidth() / 2;

		popupWindow.showAsDropDown(parent, 0, 0);
		// popupWindow.showAtLocation(parent, Gravity.RIGHT|Gravity.TOP, 0, 0);

		lv_group.setOnItemClickListener(new OnItemClickListener()
		{

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
			{

				if (popupWindow != null)
				{
					popupWindow.dismiss();
				}
				switch (position)
				{
					case 0:
						menuBtn.setText(R.string.RomAll);
						if (AppConfig.curListMode != AppConfig.ROMS_MODE_ALL)
						{
							AppConfig.curListMode = AppConfig.ROMS_MODE_ALL;
							searchAndFillRoms();
						}
						break;
					case 1:
						menuBtn.setText(R.string.RomSupport);
						if (AppConfig.curListMode != AppConfig.ROMS_MODE_SUPPORT)
						{
							AppConfig.curListMode = AppConfig.ROMS_MODE_SUPPORT;
							searchAndFillRoms();
						}
						break;
					case 2:
						menuBtn.setText(R.string.RomMyFavor);
						if (AppConfig.curListMode != AppConfig.ROMS_MODE_FAVOR)
						{
							AppConfig.curListMode = AppConfig.ROMS_MODE_FAVOR;
							searchAndFillRoms();
						}
						break;
					case 3:
						showSelectBoardDlg();
						break;
					case 4:
						showSelectGameTypeDlg();
						break;
				}
			}
		});
	}

	void showRomOperationDlg()
	{
		DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener()
		{

			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				// TODO Auto-generated method stub

				if (which == 0) // add to favor
				{
					HashMap<String, Object> map = listItem.get(rowId);
					String path = (String) map.get("GamePath");
				}
				else if (which == 1) // remove from favor
				{
					HashMap<String, Object> map = listItem.get(rowId);
					String path = (String) map.get("GamePath");
					if (AppConfig.curListMode == AppConfig.ROMS_MODE_FAVOR)
					{
						searchAndFillRoms();
					}
				}
				else if (which == 2)
				{
					OnClickListener yesListener = new OnClickListener()
					{

						@Override
						public void onClick(DialogInterface dialog, int which)
						{
							// TODO Auto-generated method stub
							HashMap<String, Object> map = listItem.get(rowId);
							String path = (String) map.get("GamePath");

							File file = new File(path);
							if (file.delete())
							{
								searchAndFillRoms();
							}
						}
					};
					new AlertDialog.Builder(GameListAct.this).setTitle(R.string.DlgTitle).setMessage(R.string.DlgMsgDeleteFile).setPositiveButton(R.string.DlgYes, yesListener)
							.setNegativeButton(R.string.DlgNo, null).show();
				}
			}
		};

		Builder b = new AlertDialog.Builder(this);
		String[] group = new String[]
		{ getResources().getString(R.string.RomAddFavor), getResources().getString(R.string.RomDelFavor), getResources().getString(R.string.RomDelete)
		};
		b.setItems(group, clickListener);

		AlertDialog dlg = b.create();
		dlg.setCanceledOnTouchOutside(true);
		dlg.show();
	}

	void showSelectBoardDlg()
	{
		DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener()
		{

			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				// TODO Auto-generated method stub
				final int[] ID = new int[]
				{ R.string.BoardCPS1, R.string.BoardCPS2, R.string.BoardCPS3, R.string.BoardNEOGEO, R.string.BoardPGM, R.string.BoardOthers
				};
				menuBtn.setText(ID[which]);
				AppConfig.curListMode = AppConfig.ROMS_MODE_BOARD;
				AppConfig.curBoardType = which;
				searchAndFillRoms();
			}
		};

		Builder b = new AlertDialog.Builder(this);
		String[] group = new String[]
		{ getResources().getString(R.string.BoardCPS1), getResources().getString(R.string.BoardCPS2), getResources().getString(R.string.BoardCPS3), getResources().getString(R.string.BoardNEOGEO),
				getResources().getString(R.string.BoardPGM), getResources().getString(R.string.BoardOthers)
		};
		b.setItems(group, clickListener);

		AlertDialog dlg = b.create();
		dlg.setCanceledOnTouchOutside(true);
		dlg.show();
	}

	void showSelectGameTypeDlg()
	{
		DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener()
		{

			@Override
			public void onClick(DialogInterface dialog, int which)
			{
				// TODO Auto-generated method stub
				final int[] ID = new int[]
				{ R.string.TypeFight, R.string.TypeAction, R.string.TypeShoot, R.string.TypeSports, R.string.TypeCasual, R.string.TypeOthers
				};
				menuBtn.setText(ID[which]);
				AppConfig.curListMode = AppConfig.ROMS_MODE_TYPE;
				AppConfig.curGameType = which;
				searchAndFillRoms();
			}
		};

		Builder b = new AlertDialog.Builder(this);
		String[] group = new String[]
		{ getResources().getString(R.string.TypeFight), getResources().getString(R.string.TypeAction), getResources().getString(R.string.TypeShoot), getResources().getString(R.string.TypeSports),
				getResources().getString(R.string.TypeCasual), getResources().getString(R.string.TypeOthers)
		};
		b.setItems(group, clickListener);

		AlertDialog dlg = b.create();
		dlg.setCanceledOnTouchOutside(true);
		dlg.show();
	}
	
}
*/